package mylab.starters.mybatis.template.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import mylab.base.model.entity.Entity;
import mylab.starters.mybatis.annotation.WriteTransactional;
import mylab.starters.mybatis.template.SuperMapper;
import mylab.starters.mybatis.template.SuperService;

import java.io.Serializable;
import java.util.List;

public abstract class SuperServiceImpl<
        K extends Serializable,
        E extends Entity<K>,
        M extends SuperMapper<E>>
        extends ServiceImpl<M, E>
        implements SuperService<K, E> {

    @Override
    public K insertIgnore(E entity) {
        baseMapper.insertIgnore(entity);
        return entity.getId();
    }

    @WriteTransactional
    @Override
    public int insertIgnoreBatch(List<E> entityList) {
        return baseMapper.insertIgnoreBatch(entityList);
    }

    @WriteTransactional
    @Override
    public int insertBatch(List<E> entityList) {
        return baseMapper.insertBatch(entityList);
    }

    @WriteTransactional
    @Override
    public boolean updateAllById(E entity) {
        return baseMapper.updateAllById(entity) > 0;
    }

}
